package person.bing.fbcloud.config;

import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author: mengfanbing
 * @date: 2020/5/25 14:48
 */
@Component
//@AllArgsConstructor
public class SocketServerConfig {
//    @EventListener(classes = SpringApplicationRunListener.class)
/*{
    System.out.println("============我是socket server，我要启动了哦==============");
    ServerSocket serverSocket = null;
    try {
        serverSocket = new ServerSocket(8090);
        Socket socket = serverSocket.accept();
        socket.setKeepAlive(true);
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        inputStream.read(bytes);
        System.out.println(new String(bytes));
//        System.out.println("======================我应该是启动成功了===============================");
    } catch (IOException e) {
        e.printStackTrace();
    }
}*/
    public static void init() throws IOException {
        System.out.println("============我是socket server，我要启动了哦==============");
        ServerSocket serverSocket = new ServerSocket(8090);
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        inputStream.read(bytes);
        System.out.println(new String(bytes));
        System.out.println("======================我应该是启动成功了===============================");
    }
}
